
package com.yuan.hibernate;

import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * A data access object (DAO) providing persistence and search support for
 * Config entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.yuan.hibernate.Config
 * @author MyEclipse Persistence Tools
 */
@SuppressWarnings("rawtypes")
public class ConfigDAO extends BaseHibernateDAO {
    private static final Logger log = LoggerFactory.getLogger(ConfigDAO.class);
    // property constants
    public static final String RUN = "run";
    public static final String COMPANYNAME = "companyname";
    public static final String SN = "sn";
    public static final String URL = "url";
    public static final String _夏冬 = "夏冬";

    public void save(Config transientInstance) {
        log.debug("saving Config instance");
        try {
            getSession().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }

    public void delete(Config persistentInstance) {
        log.debug("deleting Config instance");
        try {
            getSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }

    public Config findById(java.lang.Integer id) {
        log.debug("getting Config instance with id: " + id);
        try {
            Config instance = (Config) getSession()
                    .get("com.yuan.hibernate.Config", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }

    public List findByExample(Config instance) {
        log.debug("finding Config instance by example");
        try {
            List results = getSession()
                    .createCriteria("com.yuan.hibernate.Config")
                    .add(Example.create(instance))
                    .list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }

    public List findByProperty(String propertyName, Object value) {
        log.debug("finding Config instance with property: " + propertyName
                + ", value: " + value);
        try {
            String queryString = "from Config as model where model."
                    + propertyName + "= ?";
            Query queryObject = getSession().createQuery(queryString);
            queryObject.setParameter(0, value);
            return queryObject.list();
        } catch (RuntimeException re) {
            log.error("find by property name failed", re);
            throw re;
        }
    }

    public List findByRun(Object run
            ) {
        return findByProperty(RUN, run);
    }

    public List findByCompanyname(Object companyname
            ) {
        return findByProperty(COMPANYNAME, companyname);
    }

    public List findBySn(Object sn
            ) {
        return findByProperty(SN, sn);
    }

    public List findByUrl(Object url
            ) {
        return findByProperty(URL, url);
    }

    public List findBy夏冬(Object 夏冬
            ) {
        return findByProperty(_夏冬, 夏冬);
    }

    public List findAll() {
        log.debug("finding all Config instances");
        try {
            String queryString = "from Config";
            Query queryObject = getSession().createQuery(queryString);
            return queryObject.list();
        } catch (RuntimeException re) {
            log.error("find all failed", re);
            throw re;
        }
    }

    public Config merge(Config detachedInstance) {
        log.debug("merging Config instance");
        try {
            Config result = (Config) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(Config instance) {
        log.debug("attaching dirty Config instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

    public void attachClean(Config instance) {
        log.debug("attaching clean Config instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
}
